//
//  ViewController.m
//  02-UIViewController
//
//  Created by 曹曹 on 16/7/15.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "PresentViewController.h"

@interface ViewController ()

@end

@implementation ViewController

#pragma mark - ViewController的声明周期
// 指派初始化方法
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // 初始化方法, 不要在这个方法中加载视图
        // 在这个方法中去初始化一些数据相关的内容
    }
    return self;
}
// 加载ViewController中的view
// UINavigation UITableViewController 在loadView中 给重新写了
- (void)loadView {
    [super loadView];
    NSLog(@"%s", __func__);
    // 改变self.view
}
// 所有自定义视图的创建
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    NSLog(@"%s", __func__);
#pragma mark - 模态
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    PresentViewController *controller = [[PresentViewController alloc] init];
    // 模态动画效果
    // UIModalTransitionStyleCoverVertical默认效果, 从下往上
    // UIModalTransitionStyleFlipHorizontal左右旋转翻页
    // UIModalTransitionStyleCrossDissolve渐变效果
    // UIModalTransitionStylePartialCurl翻书效果
    controller.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    // 模态一个视图控制器
    [self presentViewController:controller animated:YES completion:nil];
}
// 注意: init, loadView, ViewDidLoad 只执行一次
// 下述方法会执行多次
// 视图将要出现时
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
// 视图已经出现时
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
// 视图将要消失时
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}
// 视图已经消失
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
// 懒加载
- (UIView *)subView {
    if (_subView == nil) {
        _subView = [UIView new];
        [self loadView];
    }
    return _subView;
}
#pragma mark - 收到内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    // 释放部分内存资源
    // 把未显示在屏幕上的资源置空
}

@end
